import Service from './$axios'
import { appName } from '../config';
/**
   * 上传文件
   * @params {string} name - 文件名称
   * @params {string} fileType - 文件类型
   * @params {string} value - 文件对象
   * @return {object} 文件DTO
   */
export const uploadFile = async (name, fileType, value) => {
  console.log(value);
  const data = new window.FormData();
  let res = '';
  try {
    await data.append('file', value);
    console.log(data);
    res = await this.post(
      `/file-management/file/uploadFile/avatar/${fileType}`,
      data,
      {
        params: {
          fileTypeId: value.id
        },
        headers: {
          'Content-Type': 'multipart/form-data'
        }
      }
    );
    return res;
  } catch (error) {
    throw new Error(error.message);
  }
}
// 报告上传
export const uploadReport = async (data) => {
  try {
    return await this.post(`${appName}/plan/uploadReport`, data);
  } catch (error) {
    throw new Error(error);
  }
}
// 批号验证
export const batchNoCheck = (data) => {
  return Service({
    url: `${appName}/partManage/batchNoCheck?batchNo=${data}`,
    method: 'get',
  })
}
// Bom导入提交
export const addOrUpdate = async (da, data) => {
  return Service({
    url: `${appName}/partManage/addOrUpdate`,
    method: 'post',
    params: {
      dataJson: da
    },
    headers: {
      "Content-Type": "multipart/form-data",
    },
    data
  })
}
// 1.4 BOM导入记录导出
export const exportImportList = (data) => {
  return Service({
    url: `${appName}/partManage/exportImportList`,
    method: 'post',
    data,
    responseType: 'blob' //防止乱码
  })
}
// 生产订单--导入记录查询
export const productionOrderImportList = (data) => {
  return Service({
    url: `${appName}/partManage/productionOrderImportList`,
    method: 'post',
    data
  })
}
//  bom详情
export const productionOrderVersionDetail = (data) => {
  return Service({
    url: `${appName}/partManage/productionOrderVersionDetail`,
    method: 'post',
    data
  })
}
// 1.51生产订单--批号对比
export const produceOrderCompare = (data) => {
  return Service({
    url: `${appName}/partManage/produceOrderCompare`,
    method: 'post',
    data
  })
}
// 1.52生产订单--修改bom
export const alterBom = (data) => {
  return Service({
    url: `${appName}/partManage/alterBom`,
    method: 'post',
    data
  })
}


// 1.6详细页导出
export const exportProductDetailList = (data) => {
  return Service({
    url: `${appName}/partManage/exportProductDetailList`,
    method: 'post',
    data,
    responseType: 'blob' //防止乱码
  })
}
// 机型查询
export const modelList = () => {
  return Service({
    url: `${appName}/partManage/modelList`,
    method: 'get',
  })
}
// 1.7生产订单-查看历史版本
export const produceImportHistoryList = (batchNo, version) => {
  return Service({
    url: `${appName}/partManage/produceImportHistoryList?batchNo=${batchNo}&version=${version}`,
    method: 'get'
  })
}
// 1.8还原
export const restoreProduceImport = (batchNo, version) => {
  return Service({
    url: `${appName}/partManage/restoreProduceImport?batchNo=${batchNo}&version=${version}`,
    method: 'get'
  })
}


// 1.91生产订单删除
export const deleteBatchBom = (data) => {
  return Service({
    url: `${appName}/partManage/deleteBatchBom?${data}`,
    method: 'get'
  })
}
// 1.41生产订单--标准件模板导出
export const exportExcelDemo1 = () => {
  return Service({
    url: `${appName}/partManage/exportExcelDemo1`,
    method: 'get',
    responseType: 'blob' //防止乱码
  })
}
// 1.42生产订单--零件模板导出
export const exportExcelDemo2 = () => {
  return Service({
    url: `${appName}/partManage/exportExcelDemo2`,
    method: 'get',
    responseType: 'blob' //防止乱码
  })
}
// 1.43生产订单--周边物料模板导出
export const exportExcelDemo3 = () => {
  return Service({
    url: `${appName}/partManage/exportExcelDemo3`,
    method: 'get',
    responseType: 'blob' //防止乱码
  })
}
// 1.44生产订单--配件模板导出
export const exportExcelDemo4 = () => {
  return Service({
    url: `${appName}/partManage/exportExcelDemo4`,
    method: 'get',
    responseType: 'blob' //防止乱码
  })
}

// 1.53生产订单--bom新增
export const addBom = (data) => {
  return Service({
    url: `${appName}/partManage/addBom`,
    method: 'post',
    data
  })
}
// 1.54生产订单--bom删除
export const deleteBom = (data) => {
  return Service({
    url: `${appName}/partManage/deleteBom?${data}`,
    method: 'get',
  })
}
